<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {padding: 0;
            margin: 0;
        }
        div{
            width: 200px;
            height: 200px;
            background-color: pink;
        }
        .hide {
            display:none;
        }
        .show{
            display: block;
        }
    </style>
</head>
<body>
    <input type="button" id="btn" value="点击隐藏"><br>
    <div id="box"></div>
    
    <script>
        var btn = document.getElementById("btn");
        var box = document.getElementById("box");
        btn.onclick = function (){
            if (btn.value === "点击隐藏"){
            box.className = "hide";
            btn.value = "点击显示"
            }else{
            box.className = "show";
            btn.value = "点击隐藏"
            }
        };
        // var btn = document.getElementById("btn");
        // var box = document.getElementById("box");
        // btn.onclick = function (){
        //     if (this.value === "点击隐藏"){
        //     box.className = "hide";
        //     this.value = "点击显示"
        //     }else{
        //     box.className = "show";
        //     this.value = "点击隐藏"
        //     }
        // };
    </script>   
</body>
</html>